﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.ServiceModel.Web;
using System.Windows.Forms;

namespace CashAgent
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            try
            {

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                //读取配置文件,如果没有店铺id,店铺名称打开店铺选择界面
                string storeId = ConfigurationManager.AppSettings["storeId"];
                string storeName = ConfigurationManager.AppSettings["storeName"];
                if (string.IsNullOrEmpty(storeId) || string.IsNullOrEmpty(storeName))
                {
                    FrmStoreSelect frmStoreSelect = new FrmStoreSelect();
                    if (frmStoreSelect.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                }

                //启动服务
                IRestfulService service = new RestfulService();
                WebServiceHost _serviceHost = new WebServiceHost(service, new Uri("http://localhost:8000/DemoService"));
                _serviceHost.Open();

                Application.Run(new FrmMain());

                _serviceHost.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
